package com.rescue.controller.admin;

import com.rescue.forum.entity.ForumBoard;
import com.rescue.forum.vo.BoardVO;
import com.rescue.result.Result;
import com.rescue.service.BoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RequestMapping("/admin/forum/board")
@RestController
@Api(tags = "板块相关接口")
@Slf4j
public class BoardController {
    @Autowired
    private BoardService boardService;

    /**
     *
     * 查询所有父板块
     * @return
     */
    @ApiOperation("查询所有父板块")
    @GetMapping("/getPBoard")
    private Result<List<BoardVO>> getPBoard(){
        log.info("查询所有父板块");
        List<BoardVO> list = boardService.getPBoard();
        return Result.success(list);
    }

    /**
     * 根据父板块查询子板块
     * @param boardId
     * @return
     */
    @ApiOperation("根据父板块查询子板块")
    @GetMapping("/getBoardByP")
    private Result<List<BoardVO>> getBoardByP(Integer boardId){
        log.info("根据父板块查询子板块");
        return Result.success(boardService.getBoardByP(boardId));
    }

    /**
     * 新增板块
     * @param forumBoard
     * @return
     */
    @ApiOperation("新增板块")
    @PostMapping("/save")
    private Result save(@RequestBody ForumBoard forumBoard){
        log.info("新增板块");
        boardService.save(forumBoard);
        return Result.success();
    }

    /**
     * 删除板块
     * @param boardId
     * @return
     */
    @ApiOperation("删除板块")
    @DeleteMapping("/delete")
    private Result delete(Integer boardId){
        log.info("删除板块{}",boardId);
        boardService.deleteByBoardId(boardId);
        return Result.success();
    }

    /**
     * 修改板块
     * @param forumBoard
     * @return
     */
    @ApiOperation("修改板块")
    @PutMapping("/update")
    private Result update(@RequestBody ForumBoard forumBoard){
        log.info("修改板块");
        boardService.update(forumBoard);
        return Result.success();
    }

    /**
     * 根据boardId获取板块信息
     * @param id
     * @return
     */
    @ApiOperation("根据boardId获取板块信息")
    @GetMapping("{id}")
    private Result<ForumBoard> getById(@PathVariable Integer id){
        log.info("根据boardId获取板块信息{}",id);
        ForumBoard board = boardService.getById(id);
        return Result.success(board);
    }
}
